package com.company.zoj;

import java.util.*;

/**
 * Created by v on 17-6-4.
 */
public class Test1610 {
    private static int[] line;

    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);

        try {
            while (true) {
                line = new int[8002];
                for(int i=0;i<line.length;i++){
                    line[i]=-1;
                }
                int n = input.nextInt();
                for (int i = 0; i < n; i++) {
                    int a = input.nextInt();
                    int b = input.nextInt();
                    int c = input.nextInt();

                    for (int j = a; j < b; j++) {
                        line[j] = c;
                    }
                }

                TreeMap<Integer,Integer> map=new TreeMap<>();

                int color=-1;

                for(int i=0;i<8002;i++){
                    if(line[i]==color){
                        continue;
                    }

                    Integer integer=map.get(color);
                    if(integer==null){
                        map.put(color,1);
                    }else {
                        map.put(color,integer+1);
                    }
                    color=line[i];
                }

                Iterator<Map.Entry<Integer,Integer>> iterator=map.entrySet().iterator();

                iterator.next();

                while (iterator.hasNext()){
                    Map.Entry<Integer,Integer> entry=iterator.next();
                    System.out.println(entry.getKey()+" "+entry.getValue());
                }
                System.out.println();
            }
        }catch (Exception ex){
            return;
        }
    }
}
